package dai.ui.single

import android.view.View
import dai.ui.UITween


open class AlphaTo(val duration:Float,var dstAlpha:Float):UITween(){

    var firstExecute = false

    var ca = 1f
    var pa = 0f
    var elapsedTime = 0f

    override fun initialize(node: View) {
        ca = node.alpha
        pa = (dstAlpha - node.alpha) / duration
        elapsedTime = 0f
    }

    override fun execute(dt: Float) {
        val node = target!!
        if (!firstExecute) {
            initialize(node)
            firstExecute = true
        }

        elapsedTime += dt
        if (elapsedTime >= duration) {
            node.alpha = dstAlpha
            end = true
        } else {
            ca += pa * dt
            node.alpha = ca
        }
    }

    override fun clone(): UITween {
        return AlphaTo(duration,dstAlpha)
    }
}